{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e797c85e-26d4-4003-a3c0-dd9545e76e84",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "d4eb4f29-1478-415d-a1f6-8ba5bfc057d2",
   "metadata": {},
   "source": [
    "# 2023/01/16\n",
    "\n",
    "\n",
    "https://leetcode.com/problems/perfect-squares/\n",
    "\n",
    "\n",
    "Timeout.\n",
    "\n",
    "\n",
    "```python\n",
    "import math\n",
    "\n",
    "class Solution:\n",
    "    perfect_square_list = []\n",
    "    def numSquares(self, n: int) -> int:\n",
    "        #2023/01/16 11:49\n",
    "        if len(self.perfect_square_list) == 0:\n",
    "            perfect_square_list = []\n",
    "            i = 1\n",
    "            square = 1\n",
    "            while square <= n:\n",
    "                perfect_square_list.append(square)\n",
    "                square = i ** 2\n",
    "                i += 1\n",
    "            perfect_square_list.pop(0)\n",
    "            perfect_square_list.reverse()\n",
    "            #print(perfect_square_list)\n",
    "            self.perfect_square_list = perfect_square_list\n",
    "        else:\n",
    "            perfect_square_list = self.perfect_square_list\n",
    "        \n",
    "        self.min_number_of_perfect_squares_that_adds_up_to_the_n = math.inf\n",
    "        def find_perfect_squares_that_adds_up_to_a_number(number, path):\n",
    "            if number == 0:\n",
    "                if len(path) < self.min_number_of_perfect_squares_that_adds_up_to_the_n:\n",
    "                    print(path)\n",
    "                    self.min_number_of_perfect_squares_that_adds_up_to_the_n = len(path)\n",
    "                return\n",
    "            for index, n in enumerate(perfect_square_list):\n",
    "                if n <= number:\n",
    "                    find_perfect_squares_that_adds_up_to_a_number(number-n, path + [n])\n",
    "                # if index > max(-1, 10-len(path)) and self.min_number_of_perfect_squares_that_adds_up_to_the_n != math.inf:\n",
    "                #     break\n",
    "        \n",
    "        find_perfect_squares_that_adds_up_to_a_number(n, [])\n",
    "            \n",
    "        return self.min_number_of_perfect_squares_that_adds_up_to_the_n\n",
    "        #2023/01/16 12:30\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd4da735-0091-431c-8956-b4f3820c0e1c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
